<%@ page language="java" contentType="text/html;charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%--
  Created by IntelliJ IDEA.
  User: 轩大晨
  Date: 2019/7/12
  Time: 12:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="gzj.pojo.Moment" %>
<%@ page import="gzj.pojo.School" %>
<%@ page import="gzj.pojo.Category" %>
<%@include file="/WEB-INF/jsp/common/head.jsp"%>



    <div class="right">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>时刻</span>
        </div>
        <div class="search">
            <form method="get"
                  action="${pageContext.request.contextPath}/moment/list.html">
                <input name="method" value="query" class="input-text" type="hidden">
                <span>学校名：</span>

                <select name="school" id="school_id">
                    <c:if test="${schoolList != null }">
                        <option value="0">--请选择--</option>
                        <c:forEach var="school" items="${schoolList}">
                            <option <c:if test="${school.school_id == backSchool }">selected="selected"</c:if>
                                    value="${school.school_id}">${school.school_name}</option>
                        </c:forEach>
                    </c:if>
                </select>
                <span>时刻分类：</span>
                <select name="category" id="category_id">
                    <c:if test="${categoryList != null }">
                        <option value="0">--请选择--</option>
                        <c:forEach var="category" items="${categoryList}">
                            <option <c:if test="${category.category_id == backCategory }">selected="selected"</c:if>
                                    value="${category.category_id}">${category.category_name}</option>
                        </c:forEach>
                    </c:if>
                </select>

                <input type="hidden" name="pageIndex" value="1"/>
                <input	value="查 询" type="submit" id="searchbutton">
                <a href="${pageContext.request.contextPath}/moment/addMoment.html" >记录这一刻</a>
            </form>
        </div>
        <!--用户-->
        <table  class="providerTable" cellpadding="0" cellspacing="0">
            <tr class="firstTr">
                <th width="10%">作者</th>
                <th width="20%">概要</th>
                <th width="10%">所属分类</th>
                <th width="10%">所属学校</th>
                <th width="15%">创建时间</th>
                <th width="5%">点赞数量</th>
                <th width="5%">评论数量</th>
                <th width="15%">操作</th>
            </tr>
            <c:forEach var="moment" items="${momentList }" varStatus="status">
                <tr id="tr">
                    <td>
                        <span>${moment.author }</span>
                    </td>
                    <td>
                        <span>${moment.content }</span>
                    </td>
                    <td>
						<span>${moment.category}</span>
                    </td>
                    <td>
                        <span>${moment.school}</span>
                    </td>
                    <td>
                        <span>${moment.showDate}</span>
                    </td>
                    <td>
                        <span id="like">${moment.like}</span>
                    </td>
                    <td>
                        <span>${moment.comment}</span>
                    </td>
                    <td>
                        <span><a class="viewUser" href="${pageContext.request.contextPath}/moment/Comment.html?moment_id=${moment.moment_id}">
                            <img src="${pageContext.request.contextPath }/statics/images/read.png" alt="查看详情" title="查看详情"/></a></span>
                        <span><a class="del" href="${pageContext.request.contextPath}/moment/del.html?moment_id=${moment.moment_id}">删除</a></span>
                        <input type="button" id="addlike" name="like" value="点赞">
                        <input type="hidden" id="moment_id" value="${moment.moment_id}"/>
                    </td>
                </tr>
            </c:forEach>
        </table>
        <input type="hidden" id="totalPageCount" value="${totalPageCount}"/>
        <c:import url="rollpage.jsp">
            <c:param name="totalCount" value="${totalCount}"/>
            <c:param name="currentPageNo" value="${currentPageNo}"/>
            <c:param name="totalPageCount" value="${totalPageCount}"/>
        </c:import>
    </div>
</section>
<%@include file="/WEB-INF/jsp/common/foot.jsp"%>

<script type="text/javascript">
    var like=$("#like");

    var moment_id=$("#moment_id");



        $("#addlike").click(function () {
            alert(like.html());
            alert(parseInt(like.html())+1);
            $.ajax({
                type:"GET",
                url:path+"/moment/like.html",
                data:{moment_id:moment_id.val()},
                dataType:"json",
                success:function (data) {
                    if(data.likeResult=="true"){

                        like.innerHTML=parseInt(like.html())+1;
                        alert("点赞成功!");
                    }else if(data.likeResult=="false"){
                        alert("点赞失败!");
                    }else{
                        alert("未知错误!");
                    }
                }
            })
        });

</script>

<%--<script type="text/javascript" src="${pageContext.request.contextPath }/statics/js/userlist.js"></script>--%>


